package com.estock.platform.http.client;

import java.util.HashMap;
import java.util.Map;

import com.estock.platform.http.request.StockClientRequest;
import com.estock.platform.http.response.JSONResponse;
import com.estock.platform.http.utils.RequestUtil;

public abstract class AbstractClientProxy {

    protected ESHttpClient httpClient;

    public AbstractClientProxy(ESHttpClient stockClient) {
        this.httpClient = stockClient;
    }

    public <T extends JSONResponse> T request(
    		StockClientRequest request,
    		Class<T> responseClass) throws Exception {
    	return request(request, getRequestMethod(), responseClass);
    }
    
    public <T extends JSONResponse> T request(
    		StockClientRequest request, String requestMethod, Class<T> responseClass) throws Exception {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put(RequestUtil.HeaderType.CONTENT_TYPE, RequestUtil.ContentType.URL_ENCODED);
        return httpClient.execute(request, headers, requestMethod, responseClass);
    }
    
    protected abstract String getRequestMethod();
      
}
